package org.apache.ibatis.session;

import org.apache.ibatis.configuration.Configuration;
import org.apache.ibatis.configuration.XmlConfigBuilder;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @Classname SqlSessionFactoryBuilder
 * @Description 生成一个SqlSessionFactory对象
 * @Date 2025/1/16 13:43
 * @Author zhuzhenguo
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {
        // 获取Configuration对象
        Configuration configuration = new Configuration();
        XmlConfigBuilder xmlConfigBuilder = new XmlConfigBuilder(configuration);
        xmlConfigBuilder.parseMybatisXmlConfig(inputStream);
        // 获取SqlSessionFactory对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return defaultSqlSessionFactory;
    }

}
